package cn.yj.frame.event;

import cn.yj.frame.netty.NettyServer;
import cn.yj.register.RegisterConfig;
import org.springframework.boot.context.event.ApplicationContextInitializedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.core.env.ConfigurableEnvironment;

import java.net.InetSocketAddress;

/**
 * 在上下文关闭的时候注册服务 - 服务停止
 *
 * @author 永健
 * @since 2022-01-19 10:23
 */
public class ApplicationCloseListener implements ApplicationListener<ContextClosedEvent> {

    @Override
    public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
        // 服务停止,移除注册中心的服务
        RegisterConfig.logout();

        // 关闭netty
        NettyServer.closeServer();
    }
}
